package com.likan.chqjtgc.handler;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.likan.chqjtgc.commons.R;
import com.likan.chqjtgc.enums.HttpStatus;
import com.likan.chqjtgc.exception.BaseException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @author : liuxinghong
 * @Description :  全局统一异常处理类
 * @date: 2021/1/22 17:06
 **/
@Slf4j
public class CommonExceptionHandler {

    /** 异常处理 */
    @ExceptionHandler(Exception.class)
    public R exceptionHandler(RuntimeException runTimeException)throws Exception {
        return R.failed(HttpStatus.INTERNAL_SERVER_ERROR.value(),runTimeException.getMessage());
    }
    @ExceptionHandler
    public R errorHandler(BaseException  e) {
      return R.failed(e.getCode(),e.getMessage());
    }
}
